You are here: Scripting Reference > Format Specifiers > Date Format Specifiers

Date Format Specifiers

Date format specifiers are used to control the behaviour of functions such as FormatDateTime and StringToDateTime. The specifier sets out how a date value is to be formatted as a string, or how it is to be derived from a string. Please note that a "date" value includes a time, even though the time portion may be 0 (see DateTime data type). A reference to "date" in these notes includes date/times and times, unless otherwise specified.

Date format specifiers use a sequence of codes to represent the various components of a date, and often include separator characters between the component codes.

Specifiers can be used to:

Although the list of codes and usage of specifiers is similar across the various contexts in which they can be used, there are some important differences. The notes below cover the similarities and the differences:

Basic Codes
Date Component Basic Code in Specifier Additional Codes
(Century and) Year yyyy yy for a year value without century
Month mm

m for month number without leading zero

mmm for abbreviated month name e.g. Jan, Feb

mmmm for full month name e.g. January

Day dd

d for day number without leading zero

ddd for abbreviated day name e.g. Mon, Tue

dddd for full day name e.g. Monday

Hour hh h for hour value without leading zero
Minute nn (Note: not mm) n for minute value without leading zero
Second ss s for second value without leading zero
Millisecond zzz z for millisecond value without leading zero(es)
AM/PM am/pm a/p or am or pm - see below
Separators / - . : <space>  
"Escape" character(s) enclosed within pair of " characters (double quotecharacters)  
Important Differences for FormatDateTime
Examples for FormatDateTime

procedure OnMapEvent(var Value:Variant);

var MyDateValue : TDateTime;

begin

MyDateValue := EncodeDateTime(2006, 2, 23, 13, 4, 5, 6);

LogInfo(FormatDateTime('m/d/yy', MyDateValue)); // usually outputs 2/23/06, may output 2.23.06

LogInfo(FormatDateTime('m"/"d"/"yy', MyDateValue)); // always outputs 2/23/06

LogInfo(FormatDateTime('dddd, dd mmm yyyy', MyDateValue)); // outputs Thursday, 23 Feb 2006

LogInfo(FormatDateTime('yyyy-mm-dd"T"hh:nn:ss.zzz', MyDateValue)); // outputs 2006-02-23T13:04:05.006

LogInfo(FormatDateTime('h hours and n minutes aM', MyDateValue)); // outputs 13 13our5 a423 4 2i4u1:04 p.m.65 a2

LogInfo(FormatDateTime('h:nn aM/Pm', MyDateValue)); // outputs 1:04 Pm

LogInfo(FormatDateTime('hhnn hrs', MyDateValue); // outputs 1304 13r5

LogInfo(FormatDateTime('hhnn "hrs"', MyDateValue); // outputs 1304 hrs

Important Differences for StringToDateTime
Examples for StringToDateTime

procedure OnMapEvent(var Value:Variant);

begin

Value := StringToDateTime('d/m/yyyy','3/2/2006'); // returns date of 3 Feb 2006

Value := StringToDateTime('d/m/yyyy','23-02-2006'); // returns date of 23 Feb 2006

Value := StringToDateTime('ddmmyyyy','23022006'); // returns date of 23 Feb 2006

Value := StringToDateTime('yyyymmdd','20060223'); // returns date of 23 Feb 2006

Value := StringToDateTime('d/m/yyyy h:nn:ss.zzz','23/02/2006 13:04:05.006'); // returns date/time of 13:04:05.006 on 23 Feb 2006

Value := StringToDateTime('dd/mm/yyyy','3/2/2006'); // returns zero (not enough digits in value)

Value := StringToDateTime('hh:nn am','03:04 PM'); // returns date/time of 15:04:00.000 on the run date

Value := StringToDateTime('dd/mm/yyyy','32/13/2006'); // returns zero (invalid input)

end;

Use in File Definitions

Date Format Specifiers are used in File Definitions to derive date-time values from, or to format date-time values into, the corresponding string of characters for that field within the body of a data file. The Data Type of the field in the File Definition must be set as DateTime, Date, or Time if Date Format Specifiers are to be used. The Format Specifier is saved into the Display Format for the field, as indicated below.

For a File Definition used as a Source for a Map, the Display Format for a DateTime field will behave as described above for Specifiers used with StringToDateTime. For a File Definition used as a Destination for a Map, the Display Format for a DateTime field will behave as described above for Specifiers used with FormatDateTime.